<template>
  <div id="app">
    <router-view />
    <audio ref="audio" class="tsy" src="@/assets/audio/kefuxiaoxi.mp3"></audio>
  </div>
</template>

<script>
import websocketService from '@/services/websocket'

export default {
  name: 'App',
  data() {
      return {
        time: null
      }
  },
  mounted() {
    
    this.time = setInterval(() => {
      if (localStorage.getItem('userId')) {
        clearInterval(this.time)
        this.time = null
        websocketService.connect(localStorage.getItem('userId'))
      websocketService.addMessageHandler((data) => {

        switch(data.type) {
        case 'session_history':
        localStorage.setItem('reloadKefu',true)
          
          break; 
        case 'user_message':
        
        

        if (this.$route.name != 'kefu') {

          this.$refs.audio.play()
          this.$message.warning('有新的用户咨询客服')

        }
        break;  
      }
      })
      }
    },1000)
    

  }
}
</script>


<style>
.tsy {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
</style>